package lendingbooks.copy;

import java.lang.reflect.Type;
import java.util.Collection;

import lendingbooks.utils.ServiceCallException;
import lendingbooks.utils.ServiceManager;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class CopyDAO {

	@SuppressWarnings("unchecked")
	public Collection<Copy> getMyLibrary() {
		ServiceManager sm = new ServiceManager();
		String myLibraryServiceResponse = "";
		try {
			myLibraryServiceResponse = sm.GET(ServiceManager.SERVICE.MY_LIBRARY);
			Gson gson = new Gson();
			Type typeOfCollectionOfCopy = new TypeToken<Collection<Copy>>() {
			}.getType();
			Collection<Copy> copys = (Collection<Copy>) gson.fromJson(
					myLibraryServiceResponse, typeOfCollectionOfCopy);
			return copys;
		} catch (ServiceCallException e) {
			// TODO Auto-generated catch block
			System.out.println(myLibraryServiceResponse);
			e.printStackTrace();

		}
		return null;
	}
	
	@SuppressWarnings("unchecked")
	public Collection<Copy> getMyFriendsLibrary() {
		ServiceManager sm = new ServiceManager();
		String myLibraryServiceResponse = "";
		try {
			myLibraryServiceResponse = sm.GET(ServiceManager.SERVICE.MY_FRIENDS_LIBRARY);
			Gson gson = new Gson();
			Type typeOfCollectionOfCopy = new TypeToken<Collection<Copy>>() {
			}.getType();
			Collection<Copy> copys = (Collection<Copy>) gson.fromJson(
					myLibraryServiceResponse, typeOfCollectionOfCopy);
			return copys;
		} catch (ServiceCallException e) {
			// TODO Auto-generated catch block
			System.out.println(myLibraryServiceResponse);
			e.printStackTrace();

		}
		return null;
	}
	
	
	
}
